class Solution {
public:
    vector<string> summaryRanges(vector<int>& nums) {
        vector<string> result;

        for(int left = 0, right = 0; left < nums.size(); left = right+1)
        {
            right = left;
            while(right+1 < nums.size() && nums[right+1]-1 == nums[left])
            {
                right++;
            }
            result.emplace_back(factory(nums,left,right));
        }

        return result;
    }

    string factory(vector<int>& nums, int left, int right)
    {
        string ret;
        if(left == right)
        {
            ret = to_string(nums[left]);
        }
        else
        {
            ret += to_string(nums[left]);
            ret += "->";
            ret += to_string(nums[right]);
        }

        return ret;
    }
};
